<?php
/**
 * Class for displaying sub menu
 */
class Custom_View_Helper_SubMenu extends Zend_View_Helper_Abstract
{
	public function subMenu ()
    {
		if($this->view->subMenues)
		{
			$items = $this->view->subMenues['items'];
			$links = $this->view->subMenues['links'];
			$activeIndx = $this->view->subMenues['activeIndx'];
			$enables = $this->view->subMenues['enableMenues'];
			$routes  = (array_key_exists('linkRoutes', $this->view->subMenues))?$this->view->subMenues['linkRoutes']:array();
			
			$subHtml = '<ul style="list-style: none; display: inline;">';
			
			foreach($items as $indx => $subMenu)
			{
				if(in_array($indx, $enables))
				{
					$acive = ($activeIndx == $indx)?'class="active"':'';
					
					if($acive || strstr($links[$indx],'javascript') || strstr($links[$indx],'#'))
						$subHtml .= '<li '.$acive.'>'.$subMenu.'</li>';
					else if(isset($routes[$indx]) && $this->view->getLink($subMenu,$links[$indx],array(),$routes[$indx]))
						$subHtml .= '<li '.$acive.'>'.$this->view->getLink($subMenu,$links[$indx],array(),$routes[$indx]).'</li>';
					else if(!isset($routes[$indx]))
						$subHtml .= '<li '.$acive.'><a href="'.$this->view->baseUrl($links[$indx]).'">'.$subMenu.'</a></li>';
				}
			}

			$subHtml .= '</ul>';
			
			return $subHtml;
		}
		else
		{
			return false;
		}
	}
}
?>
